<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8"/>
    <title>新的模板</title>
    <!-- 引入Vue -->
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<!-- 准备好一个容器 -->
<div id="root">
    <h1>学校信息：</h1>
    <h2>名称：{{name}}</h2>
    <h2>地址：{{address}}</h2>
    <br/>
    <h1>学生信息</h1>
    <button type="button" @click="addSex">添加一个性别属性，默认值男</button>
    <h2>名称：{{student.name}}</h2>
    <h2 v-if="student.sex">性别：{{student.sex}}</h2>
    <h2>年龄：真实{{student.age.rAge}}, 对外{{student.age.sAge}}</h2>
    <h2>朋友们</h2>
    <ul>
        <li v-for="f, index in student.friends" :key="index">
            {{f.name}}--{{f.age}}
        </li>
    </ul>
</div>

<script type="text/javascript">
    Vue.config.productionTip = false;// 阻止 vue 在启动时生成生产提示。

    const vm = new Vue({
        el: '#root',
        data: {
            name: '泛华',
            address: '广州珠江新城',
            student: {
                name: 'tom',
                age: {
                    rAge: 40,
                    sAge: 29
                },
                friends: [
                    {name: 'jerry', age: 35},
                    {name: 'tony', age: 55}
                ]
            }
        }
        , methods: {
            addSex() {
                // Vue.set(this.student, 'sex', '男')
                this.$set(this.student, 'sex', '男')
            }
        }
    })
</script>
</body>
</html>
